<template>
	<view class="content">
		<view class="form-block" style="border-radius:30rpx 30rpx 0 0 ;">
			<view class="form-title">投诉举报</view>
			<view class="sub-title">招聘者或其公司存在违规行为</view>
			<view class="form-item">
				<view class="form-label">举报类型</view>
				<view class="form-content">
					<picker class="form-ctrl" mode="multiSelector" range-key="className" :range="category"
						@change="bindCategoryCol" @columnchange="categoryColChange" :value="categoryIndexArr">
						{{form.title}}
					</picker>
					<view class="iconfont icon-gengduo1 arrow"></view>
				</view>
			</view>
			<view class="form-item">
				<view class="form-label">举报内容</view>
				<view class="form-content">
					<textarea :auto-height="true" style="line-height: normal;min-height: 300rpx;padding: 30rpx 0;"
						maxlength="500" type="text" placeholder-class="inputPlaceholder" placeholder="请填写举报内容"
						class="form-ctrl" v-model="form.content"></textarea>
				</view>
			</view>
			<view class="btn" @click="handleSave">提交</view>
		</view>
	</view>
</template>

<script>
	import {
		getReportClassListApi,
		insertReport
	} from '@/api/report.js'
	import {
		validate
	} from '@/util/validate.js'
	export default {
		data() {
			return {
				category: [
					[],
					[]
				],
				categoryIndexArr: [0, 0],
				childArr: [],
				form: {
					content: '',
					title: '违法/违规行为,发布广告',
				},
				cid: null,
				pid: null,
				rules: {
					title: {
						name: '举报类型',
						required: true,
					},
					content: {
						name: '举报内容',
						required: true,
					}
				}
			}
		},
		methods: {
			bindCategoryCol(e) {
				let value = e.target.value;
				this.categoryIndexArr = value;
				if (this.category[0].length !== 0) {
					this.form.title = this.category[0][this.categoryIndexArr[0]].className
				};
				if (this.category[1].length !== 0) {
					this.form.title += ',' + this.category[1][this.categoryIndexArr[1]].className
				}
			},
			categoryColChange(e) {
				if (e.detail.column == 0) {
					this.category[1] = this.childArr[e.detail.value]
					this.$set(this.category, 1, this.childArr[e.detail.value])
				}
			},
			getReportClassList() {
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				getReportClassListApi({}).then((res) => {
					this.category[0] = res
					this.childArr = res.map((item) => item.modelList)
					this.category[1] = this.childArr[0]
				})
			},
			handleSave() {
				if (validate(this.form, this.rules)) {
					uni.showLoading({
						title: '提交中',
						mask: true
					})
					insertReport({
						eid: this.cid,
						pid: this.pid,
						content: this.form.content,
						classType: this.category[1][this.categoryIndexArr[1]].id
					}).then((res) => {
						uni.showModal({
							showCancel: false,
							title: '提示',
							content: '您的举报信息已提交，我们会尽快核实并处理，并将处理结果第一时间以短信的方式通知您',
							success(e) {
								if (e.confirm) {
									uni.navigateBack()
								}
							}
						})
					})
				}
			}
		},
		onLoad(e) {
			this.cid = e.id
			this.pid = e.pid
			this.getReportClassList()
		}
	}
</script>

<style lang="scss">
	page {
		background: #fff;
	}

	.content {
		width: 100%;

		.btn {
			width: 350rpx;
			height: 80rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			background: #FF7626;
			color: #fff;
			font-size: 28rpx;
			border-radius: 40rpx;
			margin: 0 auto;
			margin-top: 30rpx;
		}

		.user-photo-block {
			width: 100%;
			height: 450rpx;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;

			.user-photo {
				width: 180rpx;
				height: 180rpx;
				border-radius: 50%;
			}
		}

		.form-block {
			width: 100%;
			box-shadow: 0 0 10px 0 #efefef;
			background: #fff;
			padding: 30rpx;

			.form-title {
				font-size: 36rpx;
				font-weight: bold;
			}

			.sub-title {
				font-size: 26rpx;
				color: #999;
				margin-top: 15rpx;
			}

			.form-item {
				display: flex;
				flex-direction: column;
				border-bottom: 1px solid #efefef;
				padding-top: 30rpx;

				.form-label {
					font-size: 28rpx;
					margin-top: 10rpx;
					//color: #999;
				}

				.form-content {
					display: flex;
					flex-direction: row;
					align-items: center;

					.form-ctrl {
						height: 100rpx;
						line-height: 100rpx;
						flex-grow: 1;
						color: #999;
					}

					.arrow {
						flex-grow: 0;
						color: #999;
						font-size: 24rpx;
					}
				}
			}
		}
	}
</style>
